//
//  TopBackView.m
//  zhiche--delivery
//
//  Created by LeeBruce on 16/5/11.
//  Copyright © 2016年 LeeBruce. All rights reserved.
//

#import "TopBackView.h"
#import <Masonry.h>
#import "Header.h"
@implementation TopBackView

- (id)initViewWithFrame:(CGRect)frame
              andTitle:(NSString *)string {
    if (self = [super init]) {
        
        self.frame = frame;

        self.backgroundColor = WhiteColor;
     
        UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake((screenWidth - 150)/2, 34, 150, 16)];
        titleLabel.text = string;
        titleLabel.textColor = TitleColor;
        titleLabel.font = Font(15);
       
        titleLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:titleLabel];
        
        UIImageView *lineImageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 63.5, screenWidth, 0.5)];

        [self addSubview:lineImageV];
        
        //客服
        self.rightButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [self addSubview:self.rightButton];
        [self.rightButton setTitle:@"" forState:UIControlStateNormal];
        [self.rightButton setTintColor:[UIColor blackColor]];
        self.rightButton.titleLabel.font = Font(15);
        self.rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        
        self.rightButton.frame = CGRectMake(screenWidth - 100 - 18, 30, 100, 25);
        
        __weak typeof(self) weakSelf = self;
        
        //UIImageView *phoneImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"common_top_icon_phone"]];
        self.phoneImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"noNews"]];

        self.phoneImg.hidden = YES;
        [self.rightButton addSubview:self.phoneImg];
        [self.phoneImg mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.right.mas_equalTo(weakSelf.mas_right).offset(-13*kWidth);
            //make.size.mas_equalTo(CGSizeMake(10, 12.5));
            make.size.mas_equalTo(CGSizeMake(19*kWidth, 26*kHeight));

            make.centerY.equalTo(weakSelf.rightButton);
            
        }];
        
        
        //返回
        self.leftButton = [UIButton buttonWithType:UIButtonTypeSystem];
        //        [self.leftButton setBackgroundImage:[UIImage imageNamed:@"common_back_btn"] forState:UIControlStateNormal];
        [self addSubview:self.leftButton];
        [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.size.mas_equalTo(CGSizeMake(46, 30));
            make.left.mas_equalTo(0);
            make.centerY.equalTo(titleLabel);
            
        }];
        
        
        UIImageView *backImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"home_back"]];
        [self.leftButton addSubview:backImage];
        [backImage mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.size.mas_equalTo(CGSizeMake(10.5, 17.5));
            make.center.equalTo(_leftButton);
            
        }];
        
        
        [self.leftButton addTarget:self
                            action:@selector(backAction)
                  forControlEvents:UIControlEventTouchUpInside];
        
        [self.rightButton addTarget:self
    action:@selector(rightClick)
    forControlEvents:UIControlEventTouchUpInside];
        
    }
    return self;
}
- (void)backAction {
   
    [self.delegate backViewPopViewController];
}
- (void)rightClick {
    [self.delegate naviRightItemClick];
}
@end
